//index.js
//获取应用实例


// 导入promise请求
import http from '../../utils/http_promise.js';

Page({
    
  data: {
      words:'',
      houseList:[],
      defautImg:"/images/3.jpg",
      orderList: [
        { text: '默认排序', value: 'a' },
        { text: '好评排序', value: 'b' },
        { text: '销量排序', value: 'c' }
      ],
    
    areaList: [
      { text: '东城区', value: 0 },
      { text: '海淀区', value: 1 },
      { text: '石景山区', value: 2 }
    ],
    
    active: 'b',
    currentArea:1,
    currentPage:1,
    isLoading: false,
    isFinish:false
    
  },

  search(){
     
     wx.navigateTo({
       url: '/pages/search/search'
     })

  },
  
  onReachBottom(){

    // 判断数据是否已完成
    if(this.data.isFinish) 
    return  wx.showToast({
      title: '亲,没有更多数据了~',
      icon:'none'
    })

   // 判断是否正在加载
    if(this.isLoading) return false;

    this.getHouseList();

  },

  getHouseList(){

   // 状态变量；
    this.setData({
      isLoading:true
    })
    
    // 调用请求
    http.request({
       url:'house/list',
       data:{
          size:5,
          page:this.data.currentPage
       }
    })

    // 处理返回值
    .then(res=>{

      // 当前页是否最后一页
      if (res.data.last_page == this.data.currentPage) this.data.isFinish = true;

      let tmpArr = this.data.houseList.concat(res.data.data);

      this.setData({
        houseList: tmpArr
      })

      this.setData({
        isLoading: false
      })

      this.data.currentPage++;

    })

    
  },
 
  onLoad: function () {

     this.getHouseList();
    
  }
  
})


